/*
 * CharacterStats.h
 *
 *  Created on: Oct 8, 2011
 *  Created by: Devin Manno
 *  Updated by: Nick James, Devin Manno, John Grange
 *	Last Update: Nov 19, 2011
 */

#ifndef CHARACTERSTATS_H_
#define CHARACTERSTATS_H_

#include "Stats.h"
#include <ostream>
#include <istream>
#include <string.h>
#include <stdlib.h>


#define DELIMS ",\n"
#define MAX 250

using std::string;
using std::ostream;
using std::istream;
using std::endl;

class CharacterStats: public Stats {
private:
	int level; 				// the character's level
	int actionPoints;		// the character's remaining action points
	int hitPoints;			// the character remaining life
    int initiative;         // determines who goes first (between 0-3)

protected:

    void loadCharacterStats(istream& in)
    {
        loadStats(in);
        char *tk = NULL;// pointers to chars
        char data[MAX] = ""; //to hold line
        in.getline(data,MAX - 1, '\n');
        tk = strtok(data, DELIMS); // get next token
        level = atoi(tk);
        tk = strtok(NULL, DELIMS); // get next token
        actionPoints = atoi(tk);
        tk = strtok(NULL, DELIMS); // get next token
        hitPoints = atoi(tk);
        tk = strtok(NULL, DELIMS); // get next token
        initiative = atoi(tk);
    }

    void saveCharacterStats(ostream& out)
    {
        saveStats(out);
        out << endl << level << ',' << actionPoints << ',' << hitPoints << ',' << initiative;
    }

public:
	static const int startingPoints = 20;	// sum of total number of points allocated to agil, str, intel and conc (for characters)
	CharacterStats();
	CharacterStats(int agil, int str, int intel,
			int conc, int maxAP, int maxHP, int lvl, int AP, int HP, int init) :
				Stats(agil, str, intel, conc, maxAP, maxHP){
		level = lvl;
		actionPoints = AP;
		hitPoints = HP;

		if(init < 0)
			initiative = 0;
		else if(init > 3)
			initiative = 3;
		else
			initiative = init;
	}
	virtual ~CharacterStats();

	// getters
	int getLevel()const;
	int getHitPoints()const;
	int getActionPoints()const;
	int getInitiative()const;

	// setters
	void setCharacterStats(int agil, int str, int intel,
				int conc, int maxAP, int maxHP, int lvl, int AP, int HP);
	void setLevel(int);
	void setHitPoints(int);
	void setActionPoints(int);
	void setInitiative(int);

	int increaseHitPoints(int hp);		// increases the current hitPoints by "hp" amount, up to maxHitPoints, down to 0. Returns remaining hit points
	int increaseActionPoints(int ap);	// increases the current actionPoints by "ap" amount, up to maxActionPoints, down to 0. Returns remaining action points
};

#endif /* CHARACTERSTATS_H_ */
